package bawei.com.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import bawei.com.bilibili.R;
import bawei.com.model.bean.ReginBean;

/**
 * 作者： 南山君
 * 时间：2017/3/9.18:56
 */

public class ZoneGridViewAdapter extends BaseAdapter {

    Context context;

    List<ReginBean.DataBean> data=new ArrayList<>();

    private int[] itemIcons = new int[]{
            R.drawable.ic_category_live, R.drawable.ic_category_t13,
            R.drawable.ic_category_t1, R.drawable.ic_category_t3,
            R.drawable.ic_category_t129, R.drawable.ic_category_t4,
            R.drawable.ic_category_t36, R.drawable.ic_category_t160,
            R.drawable.ic_category_t119, R.drawable.ic_category_t155,
            R.drawable.ic_category_t165, R.drawable.ic_category_t5,
            R.drawable.ic_category_t23, R.drawable.ic_category_t11,
            R.drawable.ic_btn_game
    };

    public ZoneGridViewAdapter(Context context) {
        this.context = context;
    }

    public void addRest(List<ReginBean.DataBean> data){

        this.data.clear();
        this.data.addAll(data);
        this.notifyDataSetChanged();

    }

    @Override
    public int getCount() {

        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {

        ViewHolder viewHolder;

        if (convertView==null){

            viewHolder=new ViewHolder();

            convertView=View.inflate(context, R.layout.zonegridview,null);

            viewHolder.iv_gridview_zone= (ImageView) convertView.findViewById(R.id.iv_gridview_zone);

            viewHolder.tv_gridview_zone= (TextView) convertView.findViewById(R.id.tv_gridview_zone);

            convertView.setTag(viewHolder);

        }else {

            viewHolder= (ViewHolder) convertView.getTag();

        }

            viewHolder.iv_gridview_zone.setImageResource(itemIcons[i]);

            viewHolder.tv_gridview_zone.setText(data.get(i).getName());

        return convertView;
    }

    class ViewHolder{

        ImageView iv_gridview_zone;

        TextView tv_gridview_zone;

    }
}
